﻿using System;
using System.Collections.Generic;
using System.Text;
using Org.Eurekaa.DNJ.Settings;
using System.ComponentModel;
using System.Collections;

namespace Org.Eurekaa.DNJ.UI.DNJSettings
{
    [Serializable()]
    public class DNJAutoCompleteSettings : GenericSettingsObject
    {

        //private List<String> _source = new List<string>();
        private string _source = "";
        [Description("This field must contain either a comma separated values, or a url of a remote source returning a JSON values list (see http://jqueryui.com/demos/autocomplete/#remote for more information)")]
        [NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        public string Source
        {
            get { return _source; }
            set { _source = value; }
        }
        [Description("The minimum number of characters a user has to type before the autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.")]
        [DefaultValue(0), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        public int MinLength 
        {
            get { return this.Get<int>("minLength"); }
            set { this["minLength"] = value; }
        }

        [Description("The delay in milliseconds the autocomplete waits after a keystroke to activate itself. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive.")]
        [DefaultValue(0), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        public int Delay 
        {
            get { return this.Get<int>("delay"); }
            set { this["delay"] = value; }
        }

        public DNJAutoCompleteSettings()
        {

        }


        public override void PrepareJSON()
        {
            this["source"] = _source;

            if (_source.Contains(",")) //comma separated values
                this["source"] = new ArrayList(_source.Replace("'", "\'").Split(new char[] { ',' }));
        }
    }
}
